package org.onvivals.admin.module.ums.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onvivals.common.param.PageParam;
import org.onvivals.common.web.PageResult;
import org.onvivals.common.web.Result;
import org.onvivals.module.ums.entity.UmsUser;
import org.onvivals.module.ums.entity.UmsUserBill;
import org.onvivals.module.ums.param.UserBillParam;
import org.onvivals.module.ums.service.IUmsUserBillService;
import org.onvivals.module.ums.service.IUmsUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: Mr.ZS
 * @Date: 2024/2/20 15:37
 * @company 湖南葆龄科技有限公司
 **/
@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RequestMapping("/userBill")
public class UserBillController {

	private final IUmsUserBillService pmsMemberBillService;
	private final IUmsUserService pmsMemberService;

	@GetMapping
	public Result<PageResult<UmsUserBill>> list(UserBillParam param) {
		PageParam<UmsUserBill, UserBillParam> page = new PageParam<>(param);
		page.setDefaultOrder("create_time desc");
		IPage<UmsUserBill> pa = pmsMemberBillService.page(page, page.getWrapper());
		pa.getRecords().forEach(k -> {
			UmsUser member = pmsMemberService.getById(k.getUid());
			if (member != null) {
				k.setNickname(member.getNickname());
			}
		});
		PageResult<UmsUserBill> pageResult = new PageResult<>(pa.getRecords(), pa.getTotal());
		return Result.OK(pageResult);
	}

}
